using BunnyEater.Common.ResponseOutput;
using BunnyEater.Domain.Base;
using BunnyEater.Service.TraceableService.MaterialService;
using BunnyEater.Service.TraceableService.MaterialService.Dto;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace BunnyEater.WebAPI.Controllers.Traceable
{
    /// <summary>
    /// 物料管理控制器，提供物料相关的增删改查接口
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiExplorerSettings(GroupName = "TRACE")]
    [ApiController]
    public class MaterialController : ControllerBase
    {
        private readonly IMaterialService _materialService;

        public MaterialController(IMaterialService materialService)
        {
            _materialService = materialService;
        }

        /// <summary>
        /// 分页查询物料列表
        /// </summary>
        [HttpGet]
        public async Task<ResponseReturnsEntity<Page<MaterialListDto>>> GetPagedMaterials([FromQuery] MaterialPagedQueryDto query)
        {
            return await _materialService.GetPagedMaterialsAsync(query);
        }

        /// <summary>
        /// 根据ID获取物料
        /// </summary>
        [HttpGet]
        public async Task<ResponseReturnsEntity<MaterialListDto>> GetMaterialById(string id)
        {
            return await _materialService.GetMaterialById(id);
        }

        /// <summary>
        /// 新增物料
        /// </summary>
        [HttpPost]
        public async Task<ResponseReturnsEntity<bool>> AddMaterial(MaterialListDto dto)
        {
            return await _materialService.AddMaterial(dto);
        }

        /// <summary>
        /// 修改物料
        /// </summary>
        [HttpPost]
        public async Task<ResponseReturnsEntity<bool>> UptMaterial(MaterialListDto dto)
        {
            return await _materialService.UptMaterial(dto);
        }

        /// <summary>
        /// 删除物料（软删除）
        /// </summary>
        [HttpPost]
        public async Task<ResponseReturnsEntity<bool>> DeleteMaterial(string id)
        {
            return await _materialService.DeleteMaterial(id);
        }
    }
}